package com.lab.system.service.task;

import cn.hutool.core.collection.CollectionUtil;
import com.lab.common.enums.UserStatus;
import com.lab.system.mapper.SysUserMapper;
import com.lab.system.service.IAppointmentViolationRecordService;
import com.lab.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * 停用超过五次不来的用户
 */
@Component("stopUser")
public class StopUserTask {

    @Autowired
    private SysUserMapper userMapper;

    @Autowired
    private IAppointmentViolationRecordService appointmentViolationService;

    /**
     * 停用用户
     */
    public void stopUser() {
        List<Long> userIds = appointmentViolationService.countUser5();
        if (CollectionUtil.isEmpty(userIds)) {
            return;
        }
        userMapper.updateUserStatusByIds(userIds, UserStatus.DISABLE.getCode());
    }

}
